package com.hostapp;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Toast;

import info.axbase.app.PluginClient;
import info.axbase.appprot.ComponentRegister;
import info.axbase.appprot.Protocol;

/**
 * Auth：yujunyao
 * Since: 2016/6/2 10:48
 * Email：yujunyao@yonglibao.com
 */
public class SecondActivity extends AppCompatActivity {

    Protocol hostInterface = new Protocol() {
        @Override
        public Object call(Object o) {
            return "Hello From Host";
        }
    };

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);
        Toast.makeText(this, "Host onCreate", Toast.LENGTH_LONG).show();
        findViewById(R.id.button1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PluginClient.getInstance()
                        .launch("app-debug",
                                SecondActivity.this, false);
                ComponentRegister.getInstance().setComponent("host", hostInterface);
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Toast.makeText(this, "Second onDestroy", Toast.LENGTH_LONG).show();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        Toast.makeText(this, "Second 返回键监听", Toast.LENGTH_LONG).show();
        return super.onKeyDown(keyCode, event);
    }
}
